﻿using System.Drawing;
using System.Windows.Forms;
using DotNet.Common;

namespace System.Windows.Forms
{
    public class MultiplexLabel : Label
    {
        public event BoolInvoker FlagChanged;

        #region 变量
        bool _defaultFlag;
        public bool DefaultFlag
        {
            get { return _defaultFlag; }
            set
            {
                _defaultFlag = value;

                if (value)
                {
                    base.Text = _defaultText;
                    base.BackColor = _defaultColor;
                }
                else
                {
                    base.Text = _otherText;
                    base.BackColor = _otherColor;
                }

                if (FlagChanged != null)
                {
                    FlagChanged(value);
                }
            }
        }

        string _defaultText;
        public string DefaultText
        {
            get { return _defaultText; }
            set
            {
                _defaultText = value;
                if (_defaultFlag)
                {
                    base.Text = value;
                }
            }
        }

        string _otherText;
        public string OtherText
        {
            get { return _otherText; }
            set
            {
                _otherText = value;
                if (!_defaultFlag)
                {
                    base.Text = value;
                }
            }
        }

        Color _defaultColor;
        public Color DefaultColor
        {
            get { return _defaultColor; }
            set
            {
                _defaultColor = value;
                if (_defaultFlag)
                {
                    base.BackColor = value;
                }
            }
        }

        Color _otherColor;
        public Color OtherColor
        {
            get { return _otherColor; }
            set
            {
                _otherColor = value;
                if (!_defaultFlag)
                {
                    base.BackColor = value;
                }
            }
        }
        #endregion

        #region 构造函数
        public MultiplexLabel()
        {
            _defaultFlag = true;
            _defaultColor = base.BackColor;
            _defaultText = base.Text;
        }
        #endregion
    }
}
